const crypto = require('crypto');
//数据加密
function aesEncrypt(data, key) {

  //用指定的算法和秘钥，返回一个cipher对象
  const cipher = crypto.createCipher('aes192', key)
  var crypted = cipher.update(data, 'utf8', 'hex')
  crypted += cipher.final('hex');
  return crypted;
}

//数据解密
function aesDecrypt(encrypted, key) {
  const decipher = crypto.createDecipher('aes192', key)
  var decrypted = decipher.update(encrypted, 'hex', 'utf8');
  decrypted += decipher.final('utf8')
  return decrypted;
}

var data = ' hello gp18';
var key = 'password';
var encrypted = aesEncrypt(data, key)
console.log('encrypted:', encrypted)
var decrypted = aesDecrypt(encrypted, key)
console.log('decrypted:', decrypted)

